bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "rules_java", version = "9.2.0")
bazel_dep(name = "rules_python", version = "1.7.0")
bazel_dep(name = "rules_proto", version = "7.1.0")
bazel_dep(name = "protobuf", version = "33.1")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "rules_pkg", version = "1.1.0")
bazel_dep(name = "rules_jvm_external", version = "6.9")

# required for aspect tests
bazel_dep(name = "rules_shell", version = "0.6.1")
bazel_dep(name = "rules_cc", version = "0.2.14")
bazel_dep(name = "abseil-cpp", version = "20250814.1")

# import clwb test projects for aspect tests
local_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:local.bzl", "local_repository")

local_repository(
    name = "clwb_virtual_includes_project",
    path = "clwb/tests/projects/virtual_includes",
)

local_repository(
    name = "clwb_virtual_includes_external",
    path = "clwb/tests/projects/virtual_includes/lib/external",
)

# custom rules_bazel_integration_test version, patches are required until we write our own version of these rules :c
bazel_dep(name = "rules_bazel_integration_test", version = "0.34.0")
single_version_override(
    module_name = "rules_bazel_integration_test",
    patch_strip = 1,
    patches = ["//third_party/bazel/patches:rules_bazel_integration_test.patch"],
)

# custom rules kotlin version, patches are required
bazel_dep(name = "rules_kotlin", version = "2.2.1")
single_version_override(
    module_name = "rules_kotlin",
    patch_strip = 1,
    patches = ["//third_party/kotlin/patches:strip_stdlib.patch"],
)

register_toolchains("//third_party/kotlin:toolchain")

# configure python cor rules_python
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(
    configure_coverage_tool = True,
    python_version = "3.12",
)
use_repo(python, "python_3_12", "python_versions")

# configure bazel binaries for rules_bazel_integration_test
bazel_binaries = use_extension("@rules_bazel_integration_test//:extensions.bzl", "bazel_binaries")
bazel_binaries.download(version = "6.5.0")
bazel_binaries.download(version = "7.6.2")
bazel_binaries.download(version = "8.4.2")
bazel_binaries.download(version = "9.0.0rc3")
bazel_binaries.download(version = "last_green")
use_repo(
    bazel_binaries,
    "bazel_binaries",
    "bazel_binaries_bazelisk",
    "build_bazel_bazel_6_5_0",
    "build_bazel_bazel_7_6_2",
    "build_bazel_bazel_8_4_2",
    "build_bazel_bazel_9_0_0rc3",
    "build_bazel_bazel_last_green",
)

# configure maven for rules_java_external
maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
maven.install(
    name = "maven",
    artifacts = [
        "junit:junit:4.13.2",
        "org.opentest4j:opentest4j:1.3.0",
        "org.mockito:mockito-core:5.8.0",
        "org.objenesis:objenesis:3.3",
        "net.bytebuddy:byte-buddy:1.14.0",
        "net.bytebuddy:byte-buddy-agent:1.14.10",
        "com.google.flogger:flogger:0.8",
        "com.google.flogger:flogger-system-backend:0.8",
        "com.googlecode.java-diff-utils:diffutils:1.3.0",
        # Usually, we'd get this from the JetBrains SDK, but the bundled one not aware of Bazel platforms,
        # so it fails on certain setups.
        "net.java.dev.jna:jna:5.14.0",
        "com.google.auto.value:auto-value-annotations:1.10.2",
        "com.google.auto.value:auto-value:1.10.4",
        "com.google.code.findbugs:jsr305:3.0.2",
        "com.google.code.gson:gson:2.10.1",
        "com.google.errorprone:error_prone_annotations:2.23.0",
        "com.google.guava:guava:33.3.1-jre",  # changed to jre
        "com.google.truth:truth:1.4.4",
        "com.google.j2objc:j2objc-annotations:2.8",
        "com.google.guava:failureaccess:1.0.2",
        "org.hamcrest:hamcrest-core:3.0",
        "org.jetbrains:annotations:26.0.2",
        "org.jetbrains.pty4j:pty4j:0.13.0",
        # Only required for the maintenance script, otherwise use the stdlib for the sdk
        "org.jetbrains.kotlin:kotlin-stdlib:2.1.21",
        "org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0",
    ],
    fail_if_repin_required = True,
    generate_compat_repositories = True,
    known_contributing_modules = [
        "",
        "bazel_worker_java",
        "protobuf",
    ],
    lock_file = "//:maven_install.json",
)
use_repo(
    maven,
    "com_google_guava_failureaccess",
    "com_google_guava_guava",
    "com_google_j2objc_j2objc_annotations",
    "maven",
    "org_opentest4j_opentest4j",
    "unpinned_maven",
    auto_value = "com_google_auto_value_auto_value",
    auto_value_annotations = "com_google_auto_value_auto_value_annotations",
    bytebuddy = "net_bytebuddy_byte_buddy",
    bytebuddy_agent = "net_bytebuddy_byte_buddy_agent",  # Can it be `bytebuddy-agent`? (not a legal identifier)
    diffutils = "com_googlecode_java_diff_utils_diffutils",
    error_prone_annotations = "com_google_errorprone_error_prone_annotations",
    flogger = "com_google_flogger_flogger",
    flogger_system_backend = "com_google_flogger_flogger_system_backend",
    gson = "com_google_code_gson_gson",
    hamcrest = "org_hamcrest_hamcrest_core",
    jetbrains_annotations = "org_jetbrains_annotations",
    jna = "net_java_dev_jna_jna",
    jsr305_annotations = "com_google_code_findbugs_jsr305",
    junit = "junit_junit",
    mockito = "org_mockito_mockito_core",
    objenesis = "org_objenesis_objenesis",
    ptylib = "org_jetbrains_pty4j_pty4j",
    truth = "com_google_truth_truth",
)

# install all required intellij sdks and plugins
intellij_platform = use_extension("//intellij_platform_sdk:extension.bzl", "intellij_platform")
intellij_platform.sdk(
    name = "clion",
    build_file = "//intellij_platform_sdk:BUILD.clion251",
    sha256 = "3a5e75b37445ffa9bef10667dfd4e79feac385519c7722035f890749a991533a",
    version = "2025.1.7",
)
intellij_platform.sdk(
    name = "clion",
    build_file = "//intellij_platform_sdk:BUILD.clion252",
    sha256 = "29b8cda11752215aaf273de283ea6245c9c55eb54cb5ef30e0765277eea9130a",
    version = "2025.2.4",
)
intellij_platform.sdk(
    name = "clion",
    alias = "clion_2025_3",
    build_file = "//intellij_platform_sdk:BUILD.clion253",
    sha256 = "a6658d1339ca0578e1a60e24f2b6cf5c9ba77f6e34e0131d111d74af7f014e9d",
    version = "253.28294.125-EAP-SNAPSHOT",
)
intellij_platform.plugin(
    name = "PythonCore",
    alias = "python_2025_1",
    build_file = "//intellij_platform_sdk:BUILD.python",
    sha256 = "b9cc64a4c260f7dd41e0c06b1b30ca8893be11370252cb84e6784c87e2585c54",
    version = "251.28774.11",
)
intellij_platform.plugin(
    name = "PythonCore",
    alias = "python_2025_2",
    build_file = "//intellij_platform_sdk:BUILD.python",
    sha256 = "dd58ebbc9f2fd539804e874b8f01ade391dcaac8ac7b2c6fb6c2437433a90040",
    version = "252.28238.7",
)
intellij_platform.plugin(
    name = "PythonCore",
    alias = "python_2025_3",
    build_file = "//intellij_platform_sdk:BUILD.python",
    sha256 = "fa3dc8a5038736e8c4aef5a8da42ab933d32ac9b416a6f5f900697aefe799487",
    version = "253.28294.169",
)
use_repo(intellij_platform, "clion_2025_1", "clion_2025_2", "clion_2025_3", "python_2025_1", "python_2025_2", "python_2025_3")
